package com.wenzheng.mybatisplus.util;

import com.baomidou.mybatisplus.core.metadata.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.*;
import lombok.*;

import java.util.*;

/**
 * @author tdf
 * @date 2019-10-29 14:39
 **/
@Data
public class PageUtils<T> {

	private List<T> records;
	private PageContent<T> page;

	public PageUtils(IPage<T> ipage) {
		if (ipage == null) {
			ipage = new Page<>();
		}
		this.page = new PageContent<>(ipage);
		this.records = ipage.getRecords();
	}

	public PageUtils(List<T> records, Long pageNum, Long totalCount,Long pageSize) {
		this.page = new PageContent<>(pageNum, totalCount, pageSize);
		this.records = records;
	}

	@Data
	private static class PageContent<T> {    // 1.当前页数 从页面获取
		private Long pageNum;
		// 3.总条数，从数据库获取
		private Long totalCount;
		private Long pageSize;

		// 5.每页的显示数据，数据库得到
		public PageContent(IPage<T> ipage) {
			this.pageNum = ipage.getCurrent();
			this.totalCount = ipage.getTotal();
			this.pageSize = ipage.getSize();
		}

		public PageContent(Long pageNum, Long totalCount, Long pageSize) {
			this.pageNum = pageNum;
			this.totalCount = totalCount;
			this.pageSize = pageSize;
		}
	}
}
